package com.bdqn.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.base.R;
import com.bdqn.base.logger.WebLogger;
import com.bdqn.pojo.ShopGoodsIssue;
import com.bdqn.service.ShopGoodsIssueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品问答
 *
 * @author lilibo
 * @date 2021/10/09
 */
@Api(tags="商品问答接口")
@RestController
@RequestMapping("/shopgoodsissue")
public class ShopGoodsIssueController {

    @Autowired
    private ShopGoodsIssueService shopGoodsIssueService;

    /**
     * 新增商品问答记录
     *
     * @param shopGoodsIssue
     * @return R
     */
    @ApiOperation("新增商品问答记录")
    @WebLogger("新增商品问答记录")
    @PostMapping("/add")
    public R save(@ApiParam("商品问答对象") @RequestBody ShopGoodsIssue shopGoodsIssue) {
        return new R<>(shopGoodsIssueService.save(shopGoodsIssue));
    }

    /**
     * 修改商品问答记录
     *
     * @param shopGoodsIssue
     * @return R
     */
    @ApiOperation("修改商品问答记录")
    @WebLogger("修改商品问答记录")
    @PostMapping("/update")
    public R update(@ApiParam("商品问答对象") @RequestBody ShopGoodsIssue shopGoodsIssue) {
        return new R<>(shopGoodsIssueService.updateById(shopGoodsIssue));
    }

    /**
     * 通过id删除一条商品问答记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id删除一条商品问答记录")
    @WebLogger("通过id删除一条商品问答记录")
    @PostMapping("/delete")
    public R removeById(@ApiParam("商品问答id") Integer id) {
        return new R<>(shopGoodsIssueService.removeById(id));
    }

    /**
     * 通过id查询单条商品问答记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id查询单条商品问答记录")
    @WebLogger("通过id查询单条商品问答记录")
    @GetMapping("/{id}")
    public R<ShopGoodsIssue> getById(@ApiParam("商品问答id") @PathVariable Integer id) {
        return new R<>(shopGoodsIssueService.getById(id));
    }

    /**
     * 通过商品问答信息查询商品问答记录
     *
     * @param shopGoodsIssue 商品问答信息对象
     * @return R
     */
    @ApiOperation("通过商品问答信息查询商品问答记录")
    @WebLogger("通过商品问答信息查询商品问答记录")
    @GetMapping("/list")
    public R<List<ShopGoodsIssue>> getList(@ApiParam("查询的商品问答对象") ShopGoodsIssue shopGoodsIssue) {
        return new R<>(shopGoodsIssueService.getList(shopGoodsIssue));
    }

    /**
     * 分页查询商品问答
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopGoodsIssue 商品问答
     * @return
     */
    @ApiOperation("分页查询商品问答")
    @WebLogger("分页查询商品问答")
    @GetMapping("/page")
    public R<IPage<ShopGoodsIssue>> getPage(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的商品问答对象") ShopGoodsIssue shopGoodsIssue) {
        return new R<>(shopGoodsIssueService.getPage(new Page<>(pageNo, pageSize), shopGoodsIssue));
    }

//    /**
//     * 分页查询商品问答数据
//     *
//     * @param pageNo 当前页
//     * @param pageSize 每页条数
//     * @param shopGoodsIssue 商品问答
//     * @return 返回对象中的count为数据总量
//     */
//    @ApiOperation("分页查询商品问答数据")
//    @WebLogger("分页查询商品问答数据")
//    @GetMapping("/pagelist")
//    public R<List<ShopGoodsIssue>> getPageList(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的商品问答对象") ShopGoodsIssue shopGoodsIssue) {
//        IPage<ShopGoodsIssue> page = shopGoodsIssueService.getPage(new Page<>(pageNo, pageSize), shopGoodsIssue);
//        return new R<>(page.getRecords(), page.getTotal());
//    }

    /**
     * 分页查询商品问答数据
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopGoodsIssue 商品问答
     * @return 返回对象中的count为数据总量
     */
    @ApiOperation("分页模糊查询商品问答数据")
    @WebLogger("分页模糊查询商品问答数据")
    @GetMapping("/pagelist")
    public R<List<ShopGoodsIssue>> getPageList(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的商品问答对象") ShopGoodsIssue shopGoodsIssue) {
        return new R<>(shopGoodsIssueService.getList(shopGoodsIssue));
    }

}
